/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: XMQ
 * Date: 2022-05-24
 * Time: 8:22
 */
//日常代码练习(熟悉用法)
class Base {

    private int x;
    private int y;

    public Base(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public int getX() {
        return x;
    }

    public final int getY() {
        return y;
    }

    public final int sum() {
        return getX() + getY();
    }

}

class Sub extends Base {

    public Sub(int x, int y) {
        super(x, y);
    }

    //write your code here......
    public int getX() {
        return super.getX()*10;
    }

}
class TreeNode {
      int val;
      TreeNode left;
      TreeNode right;
      TreeNode() {}
      TreeNode(int val) { this.val = val; }
      TreeNode(int val, TreeNode left, TreeNode right) {
          this.val = val;
          this.left = left;
          this.right = right;
      }
  }
class Singleton {

    private static Singleton instance;

    private Singleton() {

    }

    //write your code here......
    public static Singleton getInstance(){
        if(instance == null)
            instance = new Singleton();
        return instance;
    }

}
public class Test {
    public static void main(String[] args) {
        Singleton s1 = Singleton.getInstance();
        Singleton s2 = Singleton.getInstance();
        System.out.println(s1 == s2);
    }


    public static int func(int num){
        while(true){
            int sum = 0;
            while(num / 10 != 0){
                sum += num%10;
                num = num/10;
            }
            sum += num;
            if(sum < 10) return sum;
            num = sum;
        }
    }
    public static void main2(String[] args) {
        System.out.println(func(0));
    }
    public static boolean isUnivalTree(TreeNode root) {
        if(root.left == null) return true;
        if(root.val != root.left.val){
            return false;
        }else{
            if(!isUnivalTree(root.left)){
                return false;
            }
            if(!isUnivalTree(root.right)){
                return false;
            }
        }
        return true;
    }
    public static void main1(String[] args) {
        //2,2,2,5,2
        TreeNode treeNode4 = new TreeNode(5);
        TreeNode treeNode5 = new TreeNode(2);
        TreeNode treeNode2 = new TreeNode(2,treeNode4,treeNode5);
        TreeNode treeNode3 = new TreeNode(2);
        TreeNode treeNode1 = new TreeNode(2,treeNode2,treeNode3);

        System.out.println(isUnivalTree(treeNode1));
    }
}
